package com.indusfo.spc.client.controller;

import com.indusfo.spc.annotation.UserLoginToken;
import com.indusfo.spc.client.pojo.ClientMat;
import com.indusfo.spc.client.service.ClientMatService;
import com.indusfo.spc.vo.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 客户端物料控制层
 * 
 * @author zhengd
 * @create 2019-12-20
 */
@RestController
@RequestMapping("/client/mat")
public class ClientMatController {

	@Autowired
	private ClientMatService clientMatService;

	/**
	 * 保存物料关联
	 * 
	 * @return
	 */
	@PostMapping("/saveClientMat")
	@UserLoginToken
	public JSONObject saveClientMat(@RequestBody ClientMat clientMat) {
		try {
			return JSONObject.oK(clientMatService.saveClientMat(clientMat));
		} catch (Exception e) {
			e.printStackTrace();
			return JSONObject.build(JSONObject.ERROR, e.getMessage());
		}
	}

	/**
	 * 根据批次ID和工位ID查询关键物料
	 * 
	 * @return
	 */
	@PostMapping("/queryOrderBomByBatchId")
	@UserLoginToken
	public JSONObject queryOrderBomByBatchId(@RequestBody ClientMat clientMat) {
		try {
			return JSONObject.oK(clientMatService.queryOrderBomByBatchId(clientMat));
		} catch (Exception e) {
			e.printStackTrace();
			return JSONObject.build(JSONObject.ERROR, "系统异常");
		}
	}

	/**
	 * 清除物料绑定
	 * 
	 * @return
	 */
	@PostMapping("/deleteClientMat")
	@UserLoginToken
	public JSONObject deleteClientMat(@RequestBody ClientMat clientMat) {
		try {
			return JSONObject.oK(clientMatService.deleteClientMat(clientMat));
		} catch (Exception e) {
			e.printStackTrace();
			return JSONObject.build(JSONObject.ERROR, e.getMessage());
		}
	}
	
	@PostMapping("/queryMat/{matId}")
	public JSONObject queryMat(@PathVariable("matId") Integer matId) {
		try {
			return clientMatService.queryMat(matId);
		} catch (Exception e) {
			e.printStackTrace();
			return JSONObject.build(JSONObject.ERROR, "系统异常");
		}
	}

}
